//Demo
layui.use(['form','element'], function(){
    var form = layui.form;

    //监听提交
    form.on('submit(formDemo)', function(data){
        layer.msg(JSON.stringify(data.field));
        return false;
    });
});

//表单-已通过
layui.use(['table'], function(){
    var table = layui.table;
    table.render({
        elem: '#comment'
        ,size: 'lg' //开启大尺寸样式
        ,where:{
            showComment:true
        }
        ,url:'/admin/comment/showComment'
        ,cols: [[
            {type:'checkbox'}
            // {field: 'id', title: 'id', sort: true, fixed: 'left'}
            ,{field: 'user', title: '用户名',width:150}
            ,{field: 'article', title: '文章标题',width:150}
            ,{field: 'content', title: '评论内容',width:150}
            ,{field: 'check', title: '状态',width:100,
                templet:function (check) {
                    if (check.check == false){
                        return "未通过"
                    }else if (check.check == true){
                        return "已通过"
                    }else{
                        return "已审核"
                    }
                }
            }
            ,{field: 'createTime', title: '创建时间'}
            ,{title: "操作", fixed: 'right', align: 'center', toolbar: '#bar'}
        ]]
        ,id:'selectcomment'
        ,page: true
    });
    table.on('tool(comment)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
        var id = data.id;
        if(layEvent == "update"){
            var comment = layer.open({
                type: 1,
                area: ['370px', '200px'],
                title: "修改评论"
                ,content: $("#upd_comment")
                ,shade: 0
                ,btn: ["修改","取消"]
                ,btn1:function(index,layero){
                    var update_comment = $("#update_comment").val()
                    var id = data.id
                    var formData = {
                        id:id
                        ,showComment:update_comment
                    }
                    $.ajax({
                        url:"/admin/comment/commentCheck/check"
                        ,method : "get"
                        ,data:formData
                        ,success: (response)=>{
                            if (response.code == 200){
                                alert("修改成功")
                                location.reload()
                            }else{
                                alert(response.msg)
                            }
                        }
                    });
                }
                ,cancel: function (layero, index) {//关闭按钮
                    layer.close(comment);

                },
            })
        }else if (layEvent == "delete"){
            layer.confirm('你确认要删除此评论么', {
                time: 0,
                title: '删除评论',
                btn: ['确认', '取消'],
            }, function (index) {
                $.ajax({
                    url:"/admin/comment/commentCheck/del"
                    ,method : "get"
                    ,data:{'Id':id}
                    ,success: (response)=>{
                        if (response.code == 200){
                            alert("删除成功")
                            location.reload()
                        }else{
                            alert(response.msg)
                        }
                    }
                });
            },function (index) {
                layer.close(index);
            });
        }
    });
});
//表单-未通过
layui.use(['table'], function(){
    var table = layui.table;
    table.render({
        elem: '#comment_Failed'
        ,size: 'lg' //开启大尺寸样式
        ,where:{
            showComment:false
        }
        ,url:'/admin/comment/showComment'
        ,cols:[[
            {type:'checkbox'}
            // {field: 'id', title: 'id', sort: true, fixed: 'left'}
            ,{field: 'user', title: '用户名',width:150}
            ,{field: 'article', title: '文章标题',width:150}
            ,{field: 'content', title: '评论内容',width:150}
            ,{field: 'check', title: '状态',width:100,
                templet:function (check) {
                    if (check.check == false){
                        return "未通过"
                    }else if (check.check == true){
                        return "已通过"
                    }else{
                        return "已审核"
                    }
                }
            }
            ,{field: 'createTime', title: '创建时间'}
            ,{title: "操作", fixed: 'right', align: 'center', toolbar: '#bar'}
        ]]
        ,page: true
        ,id:'comment_Failed'
    });
    table.on('tool(comment_Failed)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
        var id = data.id;
        if(layEvent == "update"){
            var comment_Failed = layer.open({
                type: 1,
                area: ['370px', '200px'],
                title: "修改评论"
                ,content: $("#upd_comment")
                ,shade: 0
                ,btn: ["修改","取消"]
                ,btn1:function(index,layero){
                    var update_user = $("#update_comment").val()
                    var formData = {
                        id:id
                        ,showComment:update_user
                    }
                    $.ajax({
                        url:"/admin/comment/commentCheck/check"
                        ,method : "get"
                        ,data:formData
                        ,success: (response)=>{
                            if (response.code == 200){
                                alert("修改成功")
                                location.reload()
                            }else{
                                alert(response.msg)
                            }
                        }
                    });
                }
                ,cancel: function (layero, index) {//关闭按钮
                    layer.close(comment_Failed);

                },
            })
        }
        else if (layEvent == "delete"){
            layer.confirm('你确认要删除此评论么', {
                time: 0,
                title: '删除评论',
                btn: ['确认', '取消'],
            }, function (index) {
                $.ajax({
                    url:"/admin/comment/commentCheck/del"
                    ,method : "get"
                    ,data:{'Id':id}
                    ,success: (response)=>{
                        if (response.code == 200){
                            alert("删除成功")
                            location.reload()
                        }else{
                            alert(response.msg)
                        }
                    }
                });
            },function (index) {
                layer.close(index);
            });
        }
    });
});
//表单-已审核
layui.use(['table'], function(){
    var table = layui.table;
    table.render({
        elem: '#comment_Audited'
        ,size: 'lg' //开启大尺寸样式
        ,where:{
            showComment:" "
        }
        ,url:'/admin/comment/showComment'
        ,cols: [[
            {type:'checkbox'}
            // {field: 'id', title: 'id', sort: true, fixed: 'left'}
            ,{field: 'user', title: '用户名',width:150}
            ,{field: 'article', title: '文章标题',width:150}
            ,{field: 'content', title: '评论内容',width:150}
            ,{field: 'check', title: '状态',width:100,
                templet:function (check) {
                    if (check.check == false){
                        return "未通过"
                    }else if (check.check == true){
                        return "已通过"
                    }else{
                        return "已审核"
                    }
                }
            }
            ,{field: 'createTime', title: '创建时间'}
            ,{title: "操作", fixed: 'right', align: 'center', toolbar: '#bar'}
        ]]
        ,page: true
        ,id:'comment_Audited'
    });
    table.on('tool(comment_Audited)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
        var id = data.id;
        if(layEvent == "update"){
            var comment_Audited = layer.open({
                type: 1,
                area: ['370px', '200px'],
                title: "修改评论"
                ,content: $("#upd_comment")
                ,shade: 0
                ,btn: ["修改","取消"]
                ,btn1:function(index,layero){
                    var update_comment = $("#update_comment").val()
                    var formData = {
                        id:id
                        ,showComment:update_comment
                    }
                    $.ajax({
                        url:"/admin/comment/commentCheck/check"
                        ,method : "get"
                        ,data:formData
                        ,success: (response)=>{
                            if (response.code == 200){
                                alert("修改成功")
                                location.reload()
                            }else{
                                alert(response.msg)
                            }
                        }
                    });
                }
                ,cancel: function (layero, index) {//关闭按钮
                    layer.close(comment_Audited);

                },
            })
        }
        else if (layEvent == "delete"){
            layer.confirm('你确认要删除此评论么', {
                time: 0,
                title: '删除评论',
                btn: ['确认', '取消'],
            }, function (index) {
                $.ajax({
                    url:"/admin/comment/commentCheck/del"
                    ,method : "get"
                    ,data:{'Id':id}
                    ,success: (response)=>{
                        if (response.code == 200){
                            alert("删除成功")
                            location.reload()
                        }else{
                            alert(response.msg)
                        }
                    }
                });
            },function (index) {
                layer.close(index);
            });
        }
    });
});


//批量删除-已通过
$(function(){
    $("#dels_comment").click(function () {
        var getids = "";
        var id_data = layui.table.checkStatus('selectcomment').data
        for (var i = 0; i < id_data.length; i+=1){
            getids += (id_data[i]['id']+",");
        }
        if (id_data.length == 0){
            alert("请选择要删除的评论")
        }else{
            layer.confirm('你确认要删除这些评论么', {
                time: 0,
                title: '批量删除',
                btn: ['确认', '取消'],
            }, function (index) {
                $.ajax({
                    url:"/admin/comment/commentCheck/dels"
                    ,method : "get"
                    ,data:{'ids':getids}
                    ,success: (response)=>{
                        if (response.code == 200){
                            alert("删除成功")
                            location.reload();
                        }else{
                            alert(response.msg)
                        }
                    }
                });
            },function (index) {
                layer.close(index);
            });
        }
    })
})
//批量修改-已通过
$(function () {
    $("#upds_comment").click(function () {
        var getids = "";
        var id_data = layui.table.checkStatus('selectcomment').data
        for (var i = 0; i < id_data.length; i+=1){
            getids += (id_data[i]['id']+",");
        }
        if (id_data.length == 0){
            alert("请选择要修改的信息")
        }else{
            var comment = layer.open({
                type: 1,
                area: ['370px', '200px'],
                title: "修改评论"
                ,content: $("#upd_comment")
                ,shade: 0
                ,btn: ["修改","取消"]
                ,btn1:function(index,layero){
                    var update_comment = $("#update_comment").val()
                    var formData = {
                        Ids:getids
                        ,showComment:update_comment
                    }
                    $.ajax({
                        url:"/admin/comment/commentCheck/checks"
                        ,method : "get"
                        ,data:formData
                        ,success: (response)=>{
                            if (response.code == 200){
                                alert("修改成功")
                                location.reload();
                            }else{
                                alert(response.msg)
                            }
                        }
                    });
                }
                ,cancel: function (layero, index) {//关闭按钮
                    layer.close(comment);

                },
            })
        }
    })
})


//批量删除-未通过
$(function(){
    $("#dels_Failed").click(function () {
        var getids = "";
        var id_data = layui.table.checkStatus('comment_Failed').data
        for (var i = 0; i < id_data.length; i+=1){
            getids += (id_data[i]['id']+",");
        }
        if (id_data.length == 0){
            alert("请选择要删除的评论")
        }else{
            layer.confirm('你确认要删除这些评论么', {
                time: 0,
                title: '批量删除',
                btn: ['确认', '取消'],
            }, function (index) {
                $.ajax({
                    url:"/admin/comment/commentCheck/dels"
                    ,method : "get"
                    ,data:{'ids':getids}
                    ,success: (response)=>{
                        if (response.code == 200){
                            alert("删除成功")
                            location.reload();
                        }else{
                            alert(response.msg)
                        }
                    }
                });
            },function (index) {
                layer.close(index);
            });
        }
    })
})
//批量修改-未通过
$(function () {
    $("#upds_Failed").click(function () {
        var getids = "";
        var ids_data = layui.table.checkStatus('comment_Failed').data
        for (var i = 0; i < ids_data.length; i+=1){
            getids += (ids_data[i]['id']+",");
        }
        if (ids_data.length == 0){
            alert("请选择要修改的评论")
        }else{
            var comment = layer.open({
                type: 1,
                area: ['370px', '200px'],
                title: "修改评论"
                ,content: $("#upd_comment")
                ,shade: 0
                ,btn: ["修改","取消"]
                ,btn1:function(index,layero){
                    var update_comment = $("#update_comment").val()
                    var formData = {
                        Ids:getids
                        ,showComment:update_comment
                    }
                    $.ajax({
                        url:"/admin/comment/commentCheck/checks"
                        ,method : "get"
                        ,data:formData
                        ,success: (response)=>{
                            if (response.code == 200){
                                alert("修改成功")
                                location.reload();
                            }else{
                                alert(response.msg)
                            }
                        }
                    });
                }
                ,cancel: function (layero, index) {//关闭按钮
                    layer.close(comment);

                },
            })
        }
    })
})


//批量删除-已审核
$(function(){
    $("#dels_Audited").click(function () {
        var getids = "";
        var idss_data = layui.table.checkStatus('comment_Audited').data
        for (var i = 0; i < idss_data.length; i+=1){
            getids += (idss_data[i]['id']+",");
        }
        if (idss_data.length == 0){
            alert("请选择要删除的信息")
        }else{
            layer.confirm('你确认要删除这些评论么', {
                time: 0,
                title: '批量评论',
                btn: ['确认', '取消'],
            }, function (index) {
                $.ajax({
                    url:"/admin/comment/commentCheck/dels"
                    ,method : "get"
                    ,data:{'ids':getids}
                    ,success: (response)=>{
                        if (response.code == 200){
                            alert("删除成功")
                            location.reload();
                        }else{
                            alert(response.msg)
                        }
                    }
                });
            },function (index) {
                layer.close(index);
            });
        }
    })
})
//批量修改-已审核
$(function () {
    $("#upds_Audited").click(function () {
        var getids = "";
        var idss_data = layui.table.checkStatus('comment_Audited').data
        for (var i = 0; i < idss_data.length; i+=1){
            getids += (idss_data[i]['id']+",");
        }
        if (idss_data.length == 0){
            alert("请选择要修改的评论")
        }else{
            var comment = layer.open({
                type: 1,
                area: ['370px', '200px'],
                title: "修改评论"
                ,content: $("#upd_comment")
                ,shade: 0
                ,btn: ["修改","取消"]
                ,btn1:function(index,layero){
                    var update_comment = $("#update_comment").val()
                    var formData = {
                        Ids:getids
                        ,showComment:update_comment
                    }
                    $.ajax({
                        url:"/admin/comment/commentCheck/checks"
                        ,method : "get"
                        ,data:formData
                        ,success: (response)=>{
                            if (response.code == 200){
                                alert("修改成功")
                                location.reload();
                            }else{
                                alert(response.msg)
                            }
                        }
                    });
                }
                ,cancel: function (layero, index) {//关闭按钮
                    layer.close(comment);

                },
            })
        }
    })
})